#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>

using namespace std;

#define BEGINS(x) namespace x {
#define ENDS(x) } // end of namespace x

// 测试指针对象

struct A {
    A() : x(0), y(0) {};
    int x, y;
};

ostream &operator<<(ostream &out, const A &a) {
    cout << a.x << " " << a.y;
    return out;
}

class Pointer {
public:
    Pointer(A *p) : p(p) {}
    A &operator*() { return *p; }
    A *operator->() { return p; }
    A *operator+(int n) { return p + n; }
    A *operator-(int n) { return p - n; }
    int operator-(const Pointer &q) { return p - q.p; }
    A &operator[](int n) { return *(p + n); }
    const A &operator*() const { return *p; }
    const A *operator->() const { return p; }
    const A *operator+(int n) const { return p + n; }
    const A *operator-(int n) const { return p - n; }
    const int operator-(const Pointer &q) const { return p - q.p; }
    const A &operator[](int n) const { return *(p + n); }

    friend ostream &operator<<(ostream &out, const Pointer &p);
private:
    A *p;
};

ostream &operator<<(ostream &out, const Pointer &p) {
    out << p.p->x << " " << p.p->y;
    return out;
}

int main() {
    A a, b;
    Pointer p = &a, q = &b;
    cout << a << endl;
    p->x = 3;
    p->y = 4;
    cout << a << endl;
    cout << *p << endl;
    cout << p << endl;
    cout << (p + 1) << endl;
    cout << (p - 1) << endl;
    cout << p - q << endl;
    cout << p[0] << endl;

    const Pointer cp = &a;
    cout << *cp << endl;
    cout << (cp + 1) << endl;
    cout << (cp - 1) << endl;
    cout << cp[0] << endl;

    return 0;
}